package cc.customer.web.myCustomer;

import cc.customer.MRecord.service.MRecordService;
import cc.customer.aiEmport.damain.CAiEmp;
import cc.customer.aiEmport.services.AiEmpServices;
import cc.customer.authorization.annotation.CurrentUser;
import cc.customer.bigEmport.damain.BigEmp;
import cc.customer.bigEmport.services.BigEmpServices;
import cc.customer.common.domain.MRecord;
import cc.customer.common.domain.QueryRequest;
import cc.customer.common.domain.ResponseBo;
import cc.customer.expCustomer.domain.ExEmp;
import cc.customer.expCustomer.services.ExEmpServices;
import cc.customer.myCustomer.damain.CusResource;
import cc.customer.myCustomer.damain.MyCustomer;
import cc.customer.myCustomer.services.PerSonServices;
import cc.customer.onschool.domain.OnSchoolResource;
import cc.customer.onschool.services.OnSchoolService;
import cc.customer.rabbit.domain.CAppNews;
import cc.customer.system.domain.MyUser;
import cc.customer.web.base.BaseController;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @MethodName: $
 * @Description: TODO
 * @Param: $
 * @Return: $
 * @Author: cunfeng
 * @Date: 2020/6/17 17:00
 **/

@Controller
@RequestMapping("/app/mrecord")
public class MRecordController extends BaseController {


    @Autowired
    private MRecordService mRecordService;

    @Autowired
    private ExEmpServices exEmpServices;

    @Autowired
    private BigEmpServices bigEmpServicesOmp;

    @Autowired
    private AiEmpServices aiEmpServices;


    @Autowired
    private OnSchoolService onSchoolService;
    @Autowired
    private PerSonServices perSonServices;

    /**
     * 添加录音上传
     *
     * @param mRecord
     * @param user
     * @return
     */
    @RequestMapping("/addMRecord")
    @ResponseBody
    public ResponseBo addMRecord(MRecord mRecord, @CurrentUser MyUser user, String status, String mType) {

        String ids = mRecord.getmCusuuid();
        if (mRecord.getmSourceType().equals("1")) {
            //推广资源客户详情 标签
            ResponseBo tuiguang = exEmpServices.appGetExEmpDetail(ids, user);
            if (0 == Integer.parseInt(tuiguang.get("code").toString())) {
                ExEmp exEmp = (ExEmp) tuiguang.get("msg");
                mRecord.setmCusMobile(exEmp.getcExMobile());
                mRecord.setmCusName(exEmp.getcExName());
            }

        } else if (mRecord.getmSourceType().equals("2")) {
            //网校资源客户详情 标签
            ResponseBo school = onSchoolService.AppFindCustomerDetailByid(ids, user);
            if (0 == Integer.parseInt(school.get("code").toString())) {
                OnSchoolResource onSchoolResource = (OnSchoolResource) school.get("msg");
                mRecord.setmCusMobile(onSchoolResource.getOsMobile());
                mRecord.setmCusName(onSchoolResource.getOsNickname());
            }
        } else if (mRecord.getmSourceType().equals("3")) {
            //大资源客户详情 标签
            ResponseBo big = bigEmpServicesOmp.AppfindAllBigEmpInfoById(ids, user);
            if (0 == Integer.parseInt(big.get("code").toString())) {
                BigEmp bigEmp = (BigEmp) big.get("msg");
                mRecord.setmCusMobile(bigEmp.getBpMobile());
                mRecord.setmCusName(bigEmp.getBpName());
            }
        } else if (mRecord.getmSourceType().equals("4")) {
            //个人资源客户详情
            ResponseBo me = perSonServices.appSelectMyCusDetail(ids, user);
            if (0 == Integer.parseInt(me.get("code").toString())) {
                MyCustomer myCustomer = (MyCustomer) me.get("data");
                mRecord.setmCusMobile(myCustomer.getMyCusMobile());
                mRecord.setmCusName(myCustomer.getMyCusName());
            }
        } else if (mRecord.getmSourceType().equals("5")) {
            //AI资源客户详情 标签
            ResponseBo AI = aiEmpServices.appFindAllAiEmpInfoById(ids, user);
            if (0 == Integer.parseInt(AI.get("code").toString())) {
                CAiEmp cAiEmp = (CAiEmp) AI.get("msg");
                mRecord.setmCusMobile(cAiEmp.getAiMobile());
                mRecord.setmCusName(cAiEmp.getAiName());
            }
        }
        mRecord.setmUserid(user.getUserUuid());
        mRecord.setmUserName(user.getNickname());
        mRecord.setmType("1");
        mRecord.setmStatus("2");
        if(StringUtils.isBlank(status)){
            status ="1";
        }

        return mRecordService.addMRecord(mRecord, user.getUserUuid(), Integer.parseInt(status));
    }

    @RequestMapping(value = "/getMRecordrList")
    @ResponseBody
    public Map<String, Object> getMRecordrList(MRecord mRecord, QueryRequest request, @CurrentUser MyUser user) {
        return super.selectByPageNumSizeOrderBy(request, () -> this.mRecordService.selectMRecord(mRecord, user));

    }
}
